package com.gxa.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.common.utils.PageUtils;
import com.gxa.common.utils.Query;
import com.gxa.modules.sys.entity.Staff;
import com.gxa.modules.sys.entity.StaffAdd;
import com.gxa.modules.sys.entity.StaffUpdate;
import com.gxa.modules.sys.entity.User;
import com.gxa.modules.sys.mapper.StaffMapper;
import com.gxa.modules.sys.service.StaffService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
@Service
public class StaffServiceImpl extends ServiceImpl<StaffMapper, Staff> implements StaffService {
    @Autowired
    private StaffMapper staffMapper;
//    @Override
//    public PageUtils queryStaff(Map<String, Object> params) {
//        String employeeName = (String)params.get("employeeName");
//        IPage<Staff> page = this.page(new Query<Staff>().getPage(params),
//                new QueryWrapper<Staff>().eq(StringUtils.isNotEmpty(employeeName),"employee_name",employeeName)
//        );
//        return new PageUtils(page);
//    }


    @Override
    public PageInfo<Staff> queryStaff(Map<String, Object> params) {

        String page1=(String) params.get("page");
        String limit1=(String)params.get("limit");
        Integer page=Integer.valueOf(page1);
        Integer limit=Integer.valueOf(limit1);

        //条件查询
        String employeeName = (String) params.get("employeeName");

        PageHelper.startPage(page,limit);

        List<Staff> houseLabels = this.staffMapper.queryStaff(employeeName);

        PageInfo<Staff> pageInfo = new PageInfo<>(houseLabels);
        return pageInfo;

    }

    @Override
    public void addStaff(StaffAdd staffAdd) {
        this.staffMapper.addStaff(staffAdd);

        int personId = staffAdd.getId();
        System.out.println("personId------->"+personId);

        int roleId = staffAdd.getRoleId();
        System.out.println("roleId------->"+roleId);

        this.staffMapper.addRoleMenu(personId,roleId);
    }

    @Override
    public void updateStaff(StaffUpdate staffUpdate) {
        this.staffMapper.updateStaff(staffUpdate);

        int personId = staffUpdate.getId();
        System.out.println("personId------->"+personId);

        int roleId = staffUpdate.getRoleId();
        System.out.println("roleId------->"+roleId);

        this.staffMapper.updateRoleMenu(personId,roleId);
    }

    @Override
    public void deleteStaff(Integer id) {
        this.staffMapper.deleteStaff(id);
        this.staffMapper.deleteRoleMenu(id);
    }

    @Override
    public Staff queryById(String id) {
        Staff staff = this.staffMapper.queryById(id);
        return staff;
    }

    @Override
    public void updateSetState(String state, String id) {
        this.staffMapper.updateSetState(state,id);
    }
}
